var photoLayer = L.photo.cluster().on('click', function (evt) {
		var photo = evt.layer.photo,
			template = '<img src="{url}" width="300" height="300" /></a><p>{caption}</p>';

		if (photo.video && (!!document.createElement('video').canPlayType('video/mp4; codecs=avc1.42E01E,mp4a.40.2'))) {
			template = '<video autoplay controls poster="{url}" width="300" height="300"><source src="{video}" type="video/mp4"/></video>';
		}; 

		evt.layer.bindPopup(L.Util.template(template, photo), {
			className: 'leaflet-popup-photo',
			minWidth: 300
		}).openPopup();
	});

	/*reqwest({
		url: 'http://turban.cartodb.com/api/v2/sql?q=SELECT latitude AS lat, longitude AS lng, image_thumb AS thumbnail, image_standard AS url, video_standard AS video, caption FROM instagram WHERE the_geom %26%26 ST_SetSRID(ST_MakeBox2D(ST_Point(5.727, 59.124), ST_Point(5.924, 59.305)), 4326)',
		success: function (data) {
			photoLayer.add(data.rows).addTo(map);
			map.fitBounds(photoLayer.getBounds());
		}
	});*/
var gs = '/point/ajax';
$.ajax({
	type: "POST",
	url: gs,
	success: function(data) {
		//console.log(data);
		var rows = [];
		for(i=0 ; i< data.length; i++){
			var photo_data = {
				lat: data[i].latitude,
				lng: data[i].longtitude,
				thumbnail : data[i].link,
				url: data[i].link,
				video: '',
				caption: data[i].name
			};
			rows.push(photo_data);
		}
		
		photoLayer.add(rows).addTo(map);
		map.fitBounds(photoLayer.getBounds());
	}
});